﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Business;
using ThoiTrang.Entities;
using System.Text;

public partial class adm_survey_log : System.Web.UI.Page
{
    #region "Page functions"

    public string ckid = "";
    public int totalRes = 0;

    private void _BindGreeting()
    {
        a_User au=a_UserService.Geta_User(Request.Params["ckid"]);
        if (au != null)
        {
            this.lblGretting.Text = "Hi " + au.Firstname + " " + au.Lastname;
        }
    }

    private void _BindRepeater()
    {
        int totalRec=0;
        this.rptSurvey.DataSource = a_VoteLogService.Geta_VoteLogList(a_VoteLogColumns.VoteDate, ThoiTrang.Data.OrderDirection.DESC,1,500,out totalRec);
        this.rptSurvey.DataBind();
    }

    private void _ReadParam()
    {
        if (Request.Params["catid"] != null && Request.Params["act"] != null)
        {
            int vid = int.Parse(Request.Params["catid"].ToString());
            a_VoteLogService.Deletea_VoteLog(vid);
            this.lblAlert.Text = "Delete sucessfully";
            this.lblAlert.Visible = true;
            this._BindRepeater();
        }
    }

    public string CreateEditDeleteCommentLink(int catid, string title)
    {
        string hLink = "";
        if (Request.Params["ckid"] != null)
        {
            hLink = "<a onclick=" + "\"" + "return confirm('Are you sure want to delete?')" + "\"" + "' href='adm_survey_log.aspx?ckid=" + Request.Params["ckid"].ToString() + "&catid=" + catid.ToString() + "&act=del" + "&fn={0}'><img src='../images/ico_delete.gif' alt='del' width='16' height='13' /></a>";
        }
        else
        {
            hLink = "<a href='adm_survey_log.aspx?catid=" + catid.ToString() + "&fn={0}'><img src='../images/ico_edit.gif' alt='edit' width='12' height='12' /></a><a href='adm_survey.aspx?catid=" + catid.ToString() + "&act=del" + "&fn={0}'><img src='../images/ico_delete.gif' alt='del' width='16' height='13' /></a><a href='adm_surveyoption.aspx?ckid=" + Request.Params["ckid"].ToString() + "&qid=" + catid.ToString() + "'>Responses</a>&nbsp;<a href='adm_surveycomment.aspx?ckid=" + Request.Params["ckid"].ToString() + "&qid=" + catid.ToString() + "&title=" + System.Web.HttpUtility.UrlEncode(title) + "'>Comments</a>";
        }
        if (Request.Params["fn"] != null && (Request.Params["fn"] != "#" | Request.Params["fn"] != ""))
        {
            hLink = hLink.Replace("{0}", Request.Params["fn"].ToString());
        }
        else
        {
            hLink = hLink.Replace("{0}", "");
        }
        return hLink;
    }

    #endregion

    #region "Event"
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this._BindRepeater();
            this._BindGreeting();
            this._ReadParam();
        }
    }
    #endregion 
   
    
}
